package com.castlzl.random.core.guid;

import com.castlzl.random.core.IdGenerator;
import lombok.Getter;

import java.util.UUID;

/**
 * 基于GUID的ID生成器实现
 * 提供高性能的UUID生成，支持无分隔符格式
 * @author leiziliang
 */
public class GuidGenerator implements IdGenerator {

    /**
     * 是否使用无分隔符格式
     */
    @Getter
    private final boolean compact;

    public GuidGenerator() {
        this(true);
    }

    public GuidGenerator(boolean compact) {
        this.compact = compact;
    }

    @Override
    public long nextId() {
        UUID uuid = UUID.randomUUID();
        return Math.abs(uuid.getMostSignificantBits());
    }

    /**
     * 批量生成指定数量的GUID
     *
     * @param size 需要生成的GUID数量
     * @return 生成的GUID数组
     */
    @Override
    public long[] nextIds(int size) {
        long[] ids = new long[size];
        for (int i = 0; i < size; i++) {
            ids[i] = nextId();
        }
        return ids;
    }

    @Override
    public String getName() {
        return "guid";
    }
}